package pchi.pchicamera.adapters;

import pchi.pchicamera.R;
import pchi.pchicamera.data.Contants;
import pchi.pchicamera.data.PhotoHolder;
import pchi.pchicamera.data.PhotosData;
import pchi.pchicamera.helpers.BitmapHelpers;
import pchi.pchicamera.helpers.LayoutHelpers;
import pchi.pchicamera.models.PhotoModel;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class AlbumAdapter extends BaseAdapter {

	PhotosData album;
	Context context;
	LayoutInflater inflater;
	float width;

	public AlbumAdapter(Context context, PhotosData album) {
		this.context = context;
		this.album = album;

		inflater = LayoutInflater.from(this.context);

		this.width = LayoutHelpers.convertToPx(context, Contants.PHOTO_WIDTH);
	}

	@Override
	public View getView(int position, View item, ViewGroup parent) {
		PhotoHolder holder;

		// if (item == null) {
		item = inflater.inflate(R.layout.photo_item, null);

		holder = new PhotoHolder();
		holder.image = (ImageView) item.findViewById(R.id.img);

		item.setTag(holder);
		/*
		 * } else { holder = (PhotoHolder) item.getTag(); }
		 */
		PhotoModel photo = this.album.getPhotos().get(position);

		BitmapHelpers.loadBitmap(photo.getPath(), holder.image, this.width,
				this.width);

		return item;
	}

	@Override
	public int getCount() {
		int result = this.album.getPhotos().size();
		return result;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.album.getPhotos().get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
}
